import re
class Content():
    def __init__(self,content):
        self.content = content
    def shopjudge(self):
        final = list()
        cont = -1
        context = -1
        tent = -1
        mach = -1

        shop_position = '('
        position = self.content.find(shop_position)
        if position != -1:
            cont = self.content[int(position) - 12:int(position) + 4]
            # print(cont)
        new_position = ')'
        new = self.content.find(new_position)
        if new != -1:
            context = self.content[int(new) - 8:int(new) + 5]
            # print(context)
        extra = '〉'
        extra_position = self.content.find(extra)
        if extra_position != -1:
            tent = self.content[int(extra_position) - 12:int(extra_position)]
            # print(tent)
        judge = '》'
        judge_position = self.content.find(judge)
        if judge_position != -1:
            mach = self.content[int(judge_position)-7:int(judge_position)]
        if context != -1:
            final.append(context)
        if cont != -1:
            final.append(cont)
        if tent != -1:
            final.append(tent)
        if mach != -1:
            final.append(mach)
        # print(final)
        final.append('null')
        return final
    def moneyjudge(self):
        money_position = '实付款￥'
        other_money_position = '合计￥'

        position = self.content.find(money_position)
        other_position = self.content.find(other_money_position)
        if position != -1:
            content = self.content[int(position):int(position) + 9]
            cost = re.findall(r'[1-9]+\.?[0-9]*', content)
            return cost
        elif other_position != -1:
            other_content = self.content[int(other_position):int(other_position) + 9]
            other_cost = re.findall(r'[1-9]+\.?[0-9]*', other_content)
            return other_cost
        else:
            cost = ['null']
            return cost
    def dingdanjudge(self):
        dingdan_position = '订单号码'
        number_list = list()
        position = self.content.find(dingdan_position)
        if position != -1:
            # print(f"'{dingdan_position}' found at position: {position}")
            content = self.content[int(position):int(position) + 23]
            number = re.findall(r"\d+\.?\d*",content)
            # print(content)
            return (number)
        else:
            # print(f"'{dingdan_position}' not found")
            number_list.append("null")
            return number_list
